package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import pojo.Customer;
import util.DataConn;
import util.MD5Util;

public class CustomerDao {
	public Customer loginByName(Customer c) {
		Customer cu = null;
		Connection conn = DataConn.getConn();
		String sql="select * from customer where c_name=? and c_pass=?";
		try {
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, c.getC_name());
			pst.setString(2,c.getC_pass());
			ResultSet rs = pst.executeQuery();
			if(rs.next()) {
				cu=new Customer();
				cu.setC_name(rs.getString("c_name"));
				cu.setC_pass(rs.getString("c_pass"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return cu;
	}
	public int addCustomer(Customer c) {                                      
		int flag=0;
		Connection conn = DataConn.getConn();
		String sql="insert into customer(c_name,c_pass)values(?,?)";
		try {
			PreparedStatement pst = conn.prepareStatement(sql);
			pst.setString(1, c.getC_name());
			pst.setString(2,c.getC_pass());
			flag=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	//余
	public int delete(String id) {
		return 0;
	}

}
